package threadcoreknowledge.stopthreads;

/**
 * catchInterruptedException 后，签名方法抛出异常
 */
public class RunThrowException implements Runnable {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new RunThrowException());
        t.start();
        Thread.sleep(1000);
        t.interrupt();
    }

    @Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
            System.out.println("go");
            try {
                throwInMethod();
            } catch (InterruptedException e) {
                System.out.println("保存日志");
                e.printStackTrace();
            }
        }
    }

    private void throwInMethod() throws InterruptedException {
        Thread.sleep(2000);
    }
}
